class FriendshipsController < ApplicationController
  before_filter :authenticate_user!

  def create
    @friend = User.find(params[:friend_id])
    current_user.be_friends_with(@friend)
    respond_to { |f| f.js }
  end

  def update
    @friendship = Friendship.find(params[:id])
    friend = User.find(@friendship.friend_id)
    @friendship.accept!
    # Bug do has_friends (o accept n atualiza a outra friendship)
    friend.friendship_for(current_user).accept!
    respond_to { |f| f.js }
  end

  def destroy
    @friendship  = Friendship.find(params[:id])
    @friendship.destroy
    respond_to { |f| f.js }
  end

end
